const express = require('express');
const app =express()
const cors = require('cors');

app.use(cors())
// 将post传参转为对象
app.use(express.urlencoded({
    extended: true
}))
//自定义全局中间件，用于获取当前定位城市信息

function lacation (req,res,next){
  req.city = req.headers["location_city"] || "西安"
  const {page,pagesize,swork} = req.query
  req.swork = swork || '全部'
  req.query.swork = req.swork
  req.start = (page - 1) * pagesize || 0
  req.pages = pagesize-1+1 || 10
  next() 
}

app.use(lacation)
app.use(require('./router/cityList'))//城市列表接口
app.use(require('./router/serve'))//城市列表接口
app.use(require('./router/consociation'))//商家入驻
app.use(require('./router/technician'))//技师入驻
app.use(require('./router/useradmins'))//用户登录
app.use(require('./router/busiadmins'))//商家登录
app.use(require('./router/facilitator'))//服务商接口
app.use(require('./router/merchent'))//门店查询接口
app.use(require('./router/addfw'))//添加服务
app.use(require('./router/addmd'))//添加门店
app.use(require('./router/addjs'))//添加技师
app.use(require('./router/fw'))//服务相关
app.use(require('./router/houtai'))//后台权限查询
app.use(require('./router/dingdan'))//新增订单
app.listen(3030,()=>{
  console.log('服务器启动成功');
})
app.use( (err,req,res,next)=>{
  console.log(err)
  res.status(500).send({code:500,msg:'服务器端错误'})
} )